package org.pasta.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConnectionJDBC implements DBConnection {
	
	private static DBConnectionJDBC instance; 
	
	private String driverName;
	private String connectionString ;
	private String username ;
	private String password ;
	
	public Connection getConnection() throws Exception {
		Connection result = null;
		try {
			Class.forName(driverName);
			result = DriverManager.getConnection(connectionString,username,password);
		} catch (SQLException e) {
			e.printStackTrace();		
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}// end getConnection.
	
	public String getDriverName() {
		return driverName;
	}
	public void setDriverName(String driverName) {
		this.driverName = driverName;
	}
	
	public String getConnectionString() {
		return connectionString;
	}

	public void setConnectionString(String connectionString) {
		this.connectionString = connectionString;
	}

	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	public static DBConnectionJDBC getInstance() {
		if( instance == null )
			instance = new DBConnectionJDBC();
		return instance;
	}
}
